//
//  KLTextFiledControl.m
//  KunLun
//
//  Created by Mac on 2017/11/29.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLTextFiledControl.h"
@interface KLTextFiledControl()
@property(nonatomic, strong) STLabel                     *leftLable;
@property(nonatomic, strong) STLabel                     *rightLable;
@end
@implementation KLTextFiledControl
- (instancetype)initWithFrame:(CGRect)frame leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle{
    if (self == [super initWithFrame:frame]) {
        self.leftLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 20, self.height)
                                                   text:leftTitle
                                              textColor:KL_firstTextColor
                                                   font:14
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentLeft];
        [self addSubview:self.leftLable];
        [NSString lableAutoAdjustWitdhWithLabel:self.leftLable];
        
        self.rightLable = [[STLabel alloc] initWithFrame:CGRectMake(self.textFiled.right + 3, 0, 20, self.height)
                                                   text:rightTitle
                                              textColor:KL_firstTextColor
                                                   font:14
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentRight ];
        [self addSubview:self.rightLable];
        [NSString lableAutoAdjustWitdhWithLabel:self.rightLable];
        self.rightLable.right = self.width;
        
        self.textFiled = [[UITextField alloc] initWithFrame:CGRectMake(self.leftLable.right + 3, 0, self.rightLable.left - 6 - self.leftLable.right, self.height - 1)];
        self.textFiled.keyboardType = UIKeyboardTypeNumberPad;
        [self addSubview:self.textFiled];
        
        self.lineView = [[UIView alloc] initWithFrame:CGRectMake(self.textFiled.left, self.textFiled.bottom, self.textFiled.width, 0.5)];
        self.lineView.backgroundColor = KL_firstTextColor;
        [self addSubview:self.lineView];

    }
    return self;
}
#pragma mark --subView

- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    
    if (self.selected) {
        self.leftLable.textColor = KL_firstTextColor;
        self.textFiled.textColor = KL_firstTextColor;
        self.lineView.backgroundColor = KL_firstTextColor;
        self.rightLable.textColor = KL_firstTextColor;
    }else{
        self.leftLable.textColor = KL_secendTextColor;
        self.textFiled.textColor = KL_secendTextColor;
        self.lineView.backgroundColor = KL_secendTextColor;
        self.rightLable.textColor = KL_secendTextColor;
    }
}
@end
@interface KLPriceFiledControl()
@property(nonatomic, strong) STLabel                     *titleLable;
@end
@implementation KLPriceFiledControl
- (instancetype)initWithFrame:(CGRect)frame leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle title:(NSString *)title{
    if (self == [super initWithFrame:frame]) {
        
        self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 120, 36)
                                                         text:title
                                                    textColor:KL_secendTextColor
                                                         font:14
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        self.titleLable.centerX = self.width / 2;
        self.titleLable.layer.cornerRadius = 5;
        self.titleLable.clipsToBounds = YES;
        self.titleLable.backgroundColor = KL_backgroundColor;
        [self addSubview:self.titleLable];
        
        self.textControl = [[KLTextFiledControl alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom + 5, self.titleLable.width, 20) leftTitle:leftTitle rightTitle:rightTitle];
        [self addSubview:self.textControl];
        
        [self addTarget:self action:@selector(onClicControl) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (void)onClicControl{
    self.selected = !self.selected;
}
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    self.textControl.selected = selected;
    if (selected) {
        self.titleLable.backgroundColor = KL_BlueBackGroundColor;
        self.titleLable.textColor = [UIColor whiteColor];
    }else{
        self.titleLable.backgroundColor = KL_backgroundColor;
        self.titleLable.textColor = KL_secendTextColor;
    }
}
@end
